$(document).ready(function() {
	$('.AcceptAnswer').click(function() {
		$('.AcceptAnswer').attr('disabled', 'disabled');
		var id=$(this).attr("id");
		$.ajax({
			url: '/AcceptAnswer/',
			type: 'POST',
			dataType: 'json',
			data: {'AnswerID': id},
			success:function(callback){
				if(callback == 'notLogin') {
					window.location = "/Accounts/login/";
				}
				else if (callback == 'ok'){
					window.location.reload();
				}
				else {
					alert(callback);
					$('.AcceptAnswer').attr('disabled', false);
				}
			}
		});

	});
	$('.AnswerDelete').click(function() {
		if(confirm('确定删除？')) {
		var id=$(this).attr("id");
		$.ajax({
			url: '/AnswerDelete/',
			type: 'POST',
			dataType: 'json',
			data: {'AnswerID': id},
			success:function(callback){
				if(callback == 'error') {
					alert(callback);
				}
				else {
					window.location = callback;
				}
			}
		});
	}
	});
	$('.AnswerPraise').click(function() {
		var id=$(this).attr("id");
		$.ajax({
			url: '/AnswerPraise/',
			type: 'GET',
			dataType: 'json',
			data: {id: id},
			success:function(callback){
				$('#'+id+'.Oppose').html(callback.opposeNum);
				$('#'+id+'.Praise').html(callback.info);
			}
		});

	});
	$('.AnswerOppose').click(function() {
		var id=$(this).attr("id");
		$.ajax({
			url: '/AnswerOppose/',
			type: 'GET',
			dataType: 'json',
			data: {id: id},
			success:function(callback){
				$('#'+id+'.Praise').html(callback.praiseNum);
				$('#'+id+'.Oppose').html(callback.info);
			}
		});

	});
});

function QuestionPraise(){
	var id=$('.QuestionOpperation').attr("id");
	$.ajax({
		url: '/QuestionPraise/',
		type: 'GET',
		dataType: 'json',
		data: {id: id},
		success:function(callback){
			$('#QuestionPraise').html(callback.info);
			$('#QuestionOppose').html(callback.opposeNum);
		}
	});
}

function QuestionDelete(){
	if(confirm('确定删除？')) {
	var id=$('.QuestionOpperation').attr("id");
	$.ajax({
		url: '/QuestionDelete/',
		type: 'POST',
		dataType: 'json',
		data: {'QuestionID': id},
		success:function(callback){
			if(callback == 'error') {
				alert(callback);
			}
			else {
				window.location = callback;
			}
		}
	});
}
}

function QuestionOppose(){
	var id=$('.QuestionOpperation').attr("id");
	$.ajax({
		url: '/QuestionOppose/',
		type: 'GET',
		dataType: 'json',
		data: {id: id},
		success:function(callback){
			$('#QuestionOppose').html(callback.info);
			$('#QuestionPraise').html(callback.praiseNum);
		}
	});
}

function likeit(){
	var id=$('.QuestionOpperation').attr("id");

	$.ajax({
		url: '/likeit/',
		type: 'GET',
		dataType: 'json',
		data: {id:id},
		success:function(callback){
			alert(callback.info);
			if(callback.info=="disliked")
			$('#like').css("color","#777");
			else
			$('#like').css("color","#f83939");
	}
	});
}
